#include <string>

#include "SynonymTable.h"



SynonymTable::SynonymTable(void) {
}

SynonymTable::~SynonymTable(void) {
}



// If the string does not exist in the SynonymTable, return INVALID_DESIGN_ENTITY.
// Otherwise, returns the DesignEntityType of this symbol
DesignEntityType SynonymTable::getDesignEntityType(const std::string& symbol) {

	std::map<string, DesignEntityType>::iterator itr = mSynonymTable.find(symbol);
	if (itr == mSynonymTable.end()) {
		return INVALID_DESIGN_ENTITY;
	}
	return itr->second;
	
}




// If string already exists in SynonymTable then return false.
// Otherwise, insert the std::pair<string, DesignEntityType> normally into the SynonymTable.
bool SynonymTable::addSynonym(DesignEntityType designEntity, const string& symbol) {	
	DesignEntityType type = getDesignEntityType(symbol);
	if ( type == INVALID_DESIGN_ENTITY ) {
		mSynonymTable.insert(pair<string, DesignEntityType> (symbol, designEntity));
		return true;
	} else return false;
}

// Returns the number of synonyms added to the table.
int SynonymTable::getNumberOfSynonyms() {
	return mSynonymTable.size();
}

// Get the synonym at the given index, returning empty string if out of bounds.
std::string SynonymTable::getSynonymAtIndex(int index) {
	// Error checking
	if (index < 0 || index >= (int)mSynonymTable.size()) {
		return "";
	}

	map<string, DesignEntityType>::iterator it = mSynonymTable.begin();
	while (index > 0) {
		it++;
		index--;
	}
	return it->first;
}